IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetUserData]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetUserData]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Frank Shen
-- =============================================
CREATE PROCEDURE [dbo].[GetUserData]
	@SessionId varchar(100), 
	@domainUserId int,
	@spName varchar(100),
	@tableName varchar(100) = null
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @tempTableName VARCHAR (300)

	EXEC GetUserData_CreateTempTable @tempTableName OUTPUT, @SessionId, @domainUserId, @spName, @tableName

	DECLARE @sql varchar (600)
	
	SET @sql = 'SELECT * FROM ' + @tempTableName
	EXEC (@sql)

END
 